package guoan.web.webCustomer;

import guoan.core.dto.DataGridModel;
import guoan.core.dto.PageResponse;
import guoan.core.dto.RestResponse;
import guoan.domain.SysConfig;
import guoan.service.SysConfigService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Preconditions;

@Controller
@RequestMapping("/webCustomer/sysConfig")
public class SysConfigController {
	protected final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private SysConfigService sysConfigService;

	/** 跳转到考试主页 */
	@RequestMapping(value = "index", method = RequestMethod.GET)
	public String index() {
		return "/webCustomer/sysConfig/index";
	}

	@RequestMapping(value = "data", method = RequestMethod.POST)
	@ResponseBody
	public PageResponse<SysConfig> data(DataGridModel dataGridModel) {
		return sysConfigService.page(dataGridModel);
	}

	/** 查看 */
	@RequestMapping(value = "show", method = RequestMethod.GET)
	public String show(Long id, Model model) {
		Preconditions.checkNotNull(id, "参数错误");
		SysConfig sc = sysConfigService.findOne(id);
		Preconditions.checkNotNull(sc, "参数错误");
		model.addAttribute("sc", sc);
		return "/webCustomer/sysConfig/show";
	}

	/** 保存 */
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public RestResponse<Boolean> update(SysConfig sc, Model model) {
		Preconditions.checkNotNull(sc, "参数错误");
		sysConfigService.save(sc);
		return RestResponse.ok(true);
	}

}
